﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Input;

namespace Origin2.Framework.Managers.Input
{
    /// <summary>
    /// Keeps track of the keyboard.
    /// </summary>
    /// <remarks> If you are using this with a custom implementation of the framework, DON'T FORGET TO CALL UPDATE! </remarks>
    public static class KeyboardManager
    {
        /// <summary>
        /// The current keyboard state
        /// </summary>
        public static KeyboardState CurrentKeyboardState { get; private set; }
        
        /// <summary>
        /// The keyboard state from the last update cycle
        /// </summary>
        public static KeyboardState PreviousKeyboardState { get; private set; }

        public static List<Keys> CurrentlyPressedKeys { get; private set; }

        public static List<Keys> PreviousPressedKeys { get; private set; }

        static KeyboardManager()
        {
            CurrentlyPressedKeys = new List<Keys>();
            PreviousPressedKeys = new List<Keys>();
        }

        /// <summary>
        /// Updates the states
        /// </summary>
        public static void Update()
        {
            PreviousKeyboardState = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();

            PreviousPressedKeys = CurrentlyPressedKeys;
            CurrentlyPressedKeys = CurrentKeyboardState.GetPressedKeys().ToList();
        }

        /// <summary>
        /// Sets the previous keyboard state to the current one, essentially removing the 
        /// </summary>
        public static void Flush()
        {
            PreviousKeyboardState = CurrentKeyboardState;
        }
    }
}
